package com.woniu.controller;

import com.woniu.entity.Result;
import com.woniu.pojo.Role;
import com.woniu.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author doujiao
 * @since 2022-10-11
 */
@RestController
@RequestMapping("/role")
@Api("角色模块")
public class RoleController extends BaseController{
    @Resource
    private IRoleService roleService;
    /**
     * 查所有
     */
    @GetMapping
    @ApiOperation("查所有")
    public Result queryAll(){
        List<Role> list = roleService.list();
        return toDataResult(list);
    }
    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public Result queryById(@PathVariable Long id){
        Role Role = roleService.getById(id);
        return toDataResult(Role);
    }

    /**
     * 增加
     */
    @PostMapping
    @ApiOperation("增加一条")
    public Result add(@RequestBody Role role){
        boolean save = roleService.save(role);
        return toResult(save);
    }
    /**
     * 编辑
     */
    @PutMapping
    @ApiOperation("编辑一条")
    public Result edit(@RequestBody Role role){
        boolean result = roleService.updateById(role);
        return toResult(result);
    }
    /**
     * 根据id删除
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除")
    public Result removeById(@PathVariable Long id){
        boolean result = roleService.removeById(id);
        return toResult(result);

    }
}
